import statis from '../../models/statis/statis'
import userinfo from '../../models/users/userInfo'
import orderSchema from '../../models/order/order'
import Admins from '../../models/admin/admin'
import idSet from '../../models/idSet'
class Statis{
    constructor(){
        this.userCount = this.userCount.bind(this)
            this.orderCount = this.orderCount.bind(this)
        this.adminCount = this.adminCount.bind(this)
    }
    async userCount(req,res,next){
        await this.apiCount()
        try {
            let date = req.params.data;
            let count = await userinfo.find({
                registe_time:date
            })
            res.send({
                status:1,
                count:count.length
            })
        }catch (e) {
            console.log(e)
            res.send({
                status:0,
                err:'ERR_GET_COUNT_FAILED',
                count:0
            })
        }
    }
    async orderCount(req,res,next){
        // res.header("Access-Control-Allow-Origin", "*");
        await this.apiCount()
        try {
            let result1 = await orderSchema.find({
                order_time:eval("/^"+req.params.data+"/gi")
            })
            res.send({status:1,count:result1.length})
        }catch (e) {
            res.send({status:0,count:0,err:"ERR_GET_ADMIN_COUNT"})
        }
    }
    async adminCount(req,res,next){
        await this.apiCount()
        // res.header("Access-Control-Allow-Origin", "*");
        try {
            let result1 = await Admins.find({
                create_time:req.params.data
            })
            res.send({status:1,count:result1.length})
        }catch (e) {
            res.send({status:0,count:0,err:"ERR_GET_ADMIN_COUNT"})
        }
    }
    async apiCount(data,origin){
        // let result = await idSet.findOne({},"api_id ")
        // console.log(result.api_id)
        // result.api_id++;
        // await result.save()
        // let statics = new statis({
        //     data,
        //     origin,
        //     id
        // })
        // await statics.save()
    }
}
export default new Statis()